import os
import time


haddown=os.listdir(os.getcwd())
#找出失败的
Failefolder=[]
for folder in haddown:
	if os.path.isdir(folder):
		secfolder=os.listdir((os.getcwd()+"\\"+folder))
		for secfile in secfolder:
			if secfile.endswith(".partial"):
				Failefolder.append(folder)


#输入文件
inputfile='D:\\zhaoqi\\sarcoma\\gdc_manifest.2017-10-31T03_09_08.395162.txt' 
downloadfile='download10086.txt'

with open(downloadfile,'w')as fw:
	fw.write('id\tfilename\tmd5\tsize\tstate\n')
	with open(inputfile) as f:
		i=0
		k=0
		filelist=f.readlines()[1:]
		for line in filelist:
			k=k+1
			myfile=(line.split('\t')[0])
			if myfile not in haddown:
				i=i+1
				fw.write(line)
			#下载失败那些
			if myfile in Failefolder:
				fw.write(line)

	print ("总共："+str(k)+"个\n已下载："+str(len(haddown))+"个\n还需下载："+str(i)+"个\n")

fuck='gdc-client.exe download -t gdc-user-token.2017-11-21T03_56_43.562Z.txt -m '+downloadfile
print (fuck)

os.system(fuck)



'''

def sleeptime(hour,min,sec):
    return hour*3600 + min*60 + sec;
second = sleeptime(0,0,60);

size=0

while 1==1:
	time.sleep(second);
	filepath='D:\\zhaoqi\\sarcoma\\06982c5e-17b1-4b68-a762-da88c9dd60c9\\e6dbe014-e60a-434b-8092-f4205a78fa24_gdc_realn_rehead.bam.partial'
	mysize=os.path.getsize(filepath)
	si=mysize-size
	print (mysize,size,si)
'''